package proeva;

public class DDoS_W {
	private double Lp;
	private double Bw;
	private int M;
	private double synSa;
	private double Delay;
	private double Lt;
	private double Ir;
	private double Ia;
	private double Ti;
	private double udpTt;
	private double synPb;
	private double UDPFlood;
	private double SYNFlood;
	
	public DDoS_W(double lp, double bw, double lt, double ir, double ia) {
		super();
		Lp = lp;
		Bw = bw;
		Lt = lt;
		Ir = ir;
		Ia = ia;
	}// UDP Flood构造函数
	
	public DDoS_W() {
		super();
	}

	//SYN Flood构造函数
	public DDoS_W(int m, double synSa, double delay, double lt, double ir,
			double ia) {
		super();
		M = m;
		this.synSa = synSa;
		Delay = delay;
		Lt = lt;
		Ir = ir;
		Ia = ia;
	}
	
	
	public void setLp(double lp) {
		Lp = lp;
	}


	public double getLp() {
		return Lp;
	}
	public void setBw(double bw) {
		Bw = bw;
	}
	public double getBw() {
		return Bw;
	}
	public void setTi(double ti) {
		Ti = ti;
	}
	public double getTi() {
		return Ti;
	}
	public void setM(int m) {
		M = m;
	}
	public int getM() {
		return M;
	}
	
	public void setSynSa(double synSa) {
		this.synSa = synSa;
	}
	public double getSynSa() {
		return synSa;
	}
	public void setDelay(double delay) {
		Delay = delay;
	}
	public double getDelay() {
		return Delay;
	}
	public void setLt(double lt) {
		Lt = lt;
	}
	public double getLt() {
		return Lt;
	}
	public void setIr(double ir) {
		Ir = ir;
	}
	public double getIr() {
		return Ir;
	}
	public void setIa(double ia) {
		Ia = ia;
	}
	public double getIa() {
		return Ia;
	}
	public void setUdpTt(double udpTt) {
		this.udpTt = udpTt;
	}
	public double getUdpTt() {
		return udpTt;
	}
	public void setSynPb(double synPb) {
		this.synPb = synPb;
	}
	public double getSynPb() {
		return synPb;
	}
	public void setUDPFlood(double uDPFlood) {
		UDPFlood = uDPFlood;
	}
	public double getUDPFlood() {
		return UDPFlood;
	}
	public void setSYNFlood(double sYNFlood) {
		SYNFlood = sYNFlood;
	}
	public double getSYNFlood() {
		return SYNFlood;
	}
	
	public long factorial( int n ) 
	{
		if(n == 0){
			return 1;
		}
		else if(n<0){
			return -1;// indicates error
		}
		else{
			return n*factorial(n-1);
		}
	}
	
	public double udpCalcT( double Lp, double Bw, double Ir, double Ia )
	{
		double mu = 1000000*Bw/8/Lp;
		double lambdaR = 1/Ir;
		double lambdaA = 1/Ia;
		double rho = (lambdaR + lambdaA)/mu;
		if(rho>=1){
			return Double.POSITIVE_INFINITY;
		}
		double Ts = 1/mu;
		double Tq = rho*Ts/2/(1-rho);
		double T = Tq+Ts;
		return T;
	}
	
	public double synCalcPb( int m, double Sa, double Sr, double Ir, double Ia)
	{
		double rhoR = Sr / Ir;
		double rhoA = Sa / Ia;
		double G = 0, Pb = 0;
		double tmp = 0;

		for (int r = 0; r <= m; r++) {
			tmp = 0;
			for (int a = 0; a <= m - r; a++) {
				tmp += Math.pow(rhoA, a) / factorial(a);
			}
			G += Math.pow(rhoR, r) / factorial(r) * tmp;

		}
		for (int r = 0; r <= m; r++) {
			Pb += Math.pow(rhoR, r) / factorial(r) * Math.pow(rhoA, m - r)
					/ factorial(m - r);
		}

		Pb = Pb / G;
		return Pb;
	}
	
	public double calcE( double Tt, double Pb, double Ti )
	{
		if( Tt == Double.POSITIVE_INFINITY )
			return Double.POSITIVE_INFINITY;
		else if( Pb == 1 )
			return Double.POSITIVE_INFINITY;
		
		return Tt+Pb*Ti/(1-Pb);
	}
}
